﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

namespace ET.Monitor.DAL
{
    public class InverterDAL
    {
        object obj = null, dlVal = null;
        string strSql = "", strErrMsg = "";
        DataTable dt = new DataTable();
        IList<Hashtable> list = new List<Hashtable>();

        InvokeWebService iw = new InvokeWebService();
        string rtdbRelationAddress = "";
        string rtdbRealTimeAddress = "";
        string rtdbNameSpace = "";
        string rtdbJudge = "";
        public InverterDAL()
        {
            rtdbRelationAddress = ConfigurationManager.ConnectionStrings["RelationURL"].ConnectionString;
            rtdbRealTimeAddress = ConfigurationManager.ConnectionStrings["RealTimeURL"].ConnectionString;
            rtdbNameSpace = ConfigurationManager.ConnectionStrings["NameSpace"].ConnectionString;
            rtdbJudge = ConfigurationManager.ConnectionStrings["Judge"].ConnectionString;
        }

        #region 根据逆变器编码获取逆变器信息
        /// <summary>
        /// 根据逆变器编码获取逆变器信息 
        /// 创    建：刘重阳  
        /// 日    期：20150106
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetInverterInfoById(string id)
        {
            strSql = @"SELECT  T_DISTRICTID ,T_UNITDESC_CN ,T_UNITID ,I_ORDER ,T_UNITDESC_EN ,A.T_MACHINEID ,B.T_COMPANYID , C.T_TYPEDESC_CN,B.T_TYPEID
                        FROM    dbo.T_BASE_UNIT A
                    LEFT JOIN  T_BASE_MACHINE B ON A.T_MACHINEID = B.T_MACHINEID
                    LEFT JOIN  T_BASE_EQUIPTYPE C ON B.T_TYPEID = C.T_TYPEID
                        WHERE  T_UNITID='" + id + "'";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });

            return dt;
        }

        #endregion

        #region 新增逆变器
        /// <summary>
        /// 新增逆变器
        /// 创    建：刘重阳  
        /// 日    期：20150107
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="parentId"></param>
        /// <param name="orgNameCn"></param>
        /// <param name="orgNameEn"></param>
        /// <param name="machineId"></param>
        /// <returns></returns>
        public bool AddInverterModel(string orgId, string parentId, string orgNameCn, string machineId, string type)
        {
            if (type == "逆变器")
            {
                DataTable dt = GetInverterOrderId(parentId);
                int maxOrderId = 1;
                if (dt != null && dt.Rows.Count > 0)
                {
                    maxOrderId = Convert.ToInt32(dt.Rows[0][0]) + 1;
                }
                strSql = "INSERT INTO T_BASE_UNIT VALUES('" + parentId + "','" + orgNameCn + "','" + orgId + "'," + maxOrderId + ",'','" + machineId + "');";

            }
            else
            {
                strSql = "INSERT INTO T_BASE_UNIT VALUES('" + parentId + "','" + orgNameCn + "','" + orgId + "','','','" + machineId + "');";
            }
            return (bool)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunNonQuery", new object[] { strSql, strErrMsg });
        }
        #endregion

        #region 根据区域编号删除区域信息
        /// <summary>
        /// 根据区域编号删除区域信息
        /// 创    建：刘重阳  
        /// 日    期：20150107
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteDistrictModelById(string id)
        {
            strSql = "DELETE FROM T_BASE_UNIT WHERE T_UNITID='" + id + "'";
            return (bool)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunNonQuery", new object[] { strSql, strErrMsg });
        }
        #endregion

        #region 根据区域编码修改区域信息
        /// <summary>
        /// 根据区域编码修改区域信息
        /// 创    建：刘重阳  
        /// 日    期：20150107
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool UpdateDistrictModel(string id, string nameCn, string machineId, int orderId)
        {
            strSql = "UPDATE T_BASE_UNIT SET T_UNITDESC_CN='" + nameCn + "',I_ORDER=" + orderId + ",T_MACHINEID='" + machineId + "' WHERE T_UNITID='" + id + "'";
            return (bool)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunNonQuery", new object[] { strSql, strErrMsg });
        }
        #endregion

        #region 根据逆变器所属区域Id获取某个电站下所有逆变器序号
        public DataTable GetInverterOrderId(string id)
        {
            strSql = @"SELECT I_ORDER AS ORDERID,T_BASE_UNIT.T_UNITID FROM dbo.T_BASE_UNIT WHERE T_DISTRICTID IN
                            (SELECT T_DISTRICTID FROM dbo.T_BASE_DISTRICT WHERE T_ORGID IN 
                                (SELECT T_ORGID  FROM T_BASE_DISTRICT WHERE T_DISTRICTID='" + id + "') ) ORDER BY I_ORDER DESC";
            DataTable dtDis = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dtDis;
        }
        #endregion

        #region 获取逆变器负荷数据
        /// <summary>
        /// 功能描述：获取逆变器负荷数据
        /// 创    建：胡进财  日    期：20141009
        /// <summary>
        /// <param name="id">电厂编码</param>
        /// <returns></returns>
        public object GetInverternPower(string id)
        {
            strSql = "select T_POWERTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        public object[] GetInverternPowers(string areaId)
        {
            strSql = "select T_UNITID from T_BASE_UNIT where T_DISTRICTID='" + areaId + "' order by T_ORDER asc";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            object[] val = new object[dt.Rows.Count];
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strSql = "select T_POWERTAG from T_BASE_POINTS_UNIT where T_UNITID='" + dt.Rows[i][0].ToString() + "'";
                    obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
                    if (obj != null)
                        val[i] = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValue", new object[] { obj.ToString(), Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").ToString()) });
                    else
                        val[i] = dlVal;
                }

            }
            return val;
        }
        #endregion

        #region 获取逆变器实时电量
        /// <summary>
        /// 功能描述：获取逆变器实时电量
        /// 创    建：胡进财  日    期：20141009
        /// <summary>
        /// <param name="id">电厂编码</param>
        /// <returns></returns>
        public object GetInverterRealDl(string id)
        {
            strSql = "select T_ELECDTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        public object[] GetInverterRealDls(string areaId)
        {
            strSql = "select T_UNITID from T_BASE_UNIT where T_DISTRICTID='" + areaId + "' order by T_ORDER asc";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            object[] val = new object[dt.Rows.Count];
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strSql = "select T_ELECTAG from T_BASE_POINTS_UNIT where T_UNITID='" + dt.Rows[i][0].ToString() + "'";
                    obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
                    if (obj != null)
                        val[i] = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValue", new object[] { obj.ToString(), Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").ToString()) });
                    else
                        val[i] = dlVal;
                }
            }
            return val;
        }
        #endregion

        #region 获取逆变器所有测点数据---->自定义趋势用
        public DataTable GetinverterPoints(string id)
        {
            if (id.IndexOf("'") > -1)
                strSql = "select T_PARAID,T_REALTIME,T_ORGID,T_PARADESC_CN,T_PARADESC_EN from T_BASE_CHARTPARAID where T_ORGID in(" + id + ")";
            else
                strSql = "select T_PARAID,T_REALTIME,T_ORGID,T_PARADESC_CN,T_PARADESC_EN from T_BASE_CHARTPARAID where T_ORGID='" + id + "'";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        #endregion

        #region 频率
        /// 功能描述：获取逆变器频率数据
        /// 创    建：胡进财  日    期：20141009
        /// <summary>
        /// <param name="id">电厂编码</param>
        /// <returns></returns>
        public object GetInverternFre(string id)
        {
            strSql = "select T_FRETAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 温度
        /// 功能描述：获取逆变器温度
        /// 创    建：胡进财  日    期：20141009
        /// <summary>
        /// <param name="id">逆变器编码</param>
        /// <returns></returns>
        public object GetInverternTemp(string id)
        {
            strSql = "select T_TEMPTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 时间段温度
        public ArrayList GetInverterTemps(string id, DateTime st, DateTime et, int count)
        {
            strSql = "select T_TEMPTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            double[] val = (double[])iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValueByStep", new object[] { obj.ToString(), st, et, count });
            //dt = (DataTable)iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValueByStartTimeAndEndTime", new object[] { obj.ToString(), Convert.ToDateTime(st), Convert.ToDateTime(et) });

            DateTime _sTime = new DateTime(1970, 1, 1);
            ArrayList arrList = new ArrayList();
            //int num = 0;
            //if (dt.Rows.Count < count)
            //{
            //    num = 1;
            //}
            //else
            //{
            //    num = dt.Rows.Count / count;
            //}
            //int dtCount = dt.Rows.Count;
            ////for (int i = 0; i < dt.Rows.Count; i++)
            //for (int i = dtCount - 1; i > -1; i--)
            //{
            //    if (i % num == 0)
            //    {
            //        if (dt.Rows[i]["D_VALUE"].ToString() == "")
            //        {
            //            continue;
            //        }
            for (int i = 0; i < val.Length; i++)
            {
                ArrayList arr = new ArrayList();
                string timeStamp = "";
                if (i == 0)
                    timeStamp = DateTimeToUTC(st).ToString();
                else
                    timeStamp = DateTimeToUTC(st.AddSeconds(count)).ToString();
                DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long lTime = long.Parse(timeStamp + "0000000");
                TimeSpan toNow = new TimeSpan(lTime);
                DateTime dtResult = dtStart.Add(toNow);

                arr.Add(Convert.ToInt64((dtResult - _sTime).TotalMilliseconds.ToString()));
                arr.Add(Math.Round(val[i], 2));
                arrList.Add(arr);
                st = st.AddSeconds(count);
            }
            //    }
            //}
            return arrList;
        }
        #endregion

        #region 汇流箱
        public DataTable GetTextBox(string id)
        {
            strSql = "";
            if (id.IndexOf("'") > -1)
                strSql = "select  T_BOXDESC_EN,T_BOXDESC_CN,T_BOXID,T_MACHINEID,T_UNITID From T_BASE_COMBINEBOX where T_UNITID in(" + id + ")";
            else
                strSql = "select  T_BOXDESC_EN,T_BOXDESC_CN,T_BOXID,T_MACHINEID,T_UNITID From T_BASE_COMBINEBOX where T_UNITID='" + id + "'";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        #endregion

        #region A相电流
        /// 功能描述：获取逆变器A相电流
        /// 创    建：胡进财  日    期：20141009
        /// <summary>
        /// <param name="id">逆变器编码</param>
        /// <returns></returns>
        public object GetInverternIacr(string id)
        {
            strSql = "select T_IACRTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region B相电流
        /// 功能描述：获取逆变器b相电流
        /// 创    建：胡进财  日    期：20141009
        /// <summary>
        /// <param name="id">逆变器编码</param>
        /// <returns></returns>
        public object GetInverternIacs(string id)
        {
            strSql = "select T_IACSTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region C相电流
        /// 功能描述：获取逆变器 C相电流
        /// 创    建：胡进财  日    期：20141009
        /// <summary>
        /// <param name="id">逆变器编码</param>
        /// <returns></returns>
        public object GetInverternIac(string id)
        {
            strSql = "select T_IACTTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region A相电压
        public object GetInverternVacr(string id)
        {
            strSql = "select T_VACRTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region B相电压
        public object GetInverternVacs(string id)
        {
            strSql = "select T_VACSTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region C相电压
        public object GetInverternVact(string id)
        {
            strSql = "select VACTTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region A相功率
        public object GetInverternPacr(string id)
        {
            strSql = "select T_PACRTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region B相功率
        public object GetInverternPacs(string id)
        {
            strSql = "select T_PACSTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region C相功率
        public object GetInverternPact(string id)
        {
            strSql = "select T_PACTTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 日发电量
        public object GetInverternElecd(string id)
        {
            strSql = "select T_ELECDTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 累计发电量
        public double GetInverternElect(string id, string st, string et)
        {
            strSql = "select isnull(SUM(D_VALUE),0) VAL,T_ORGID from T_INFO_STATISTICS where T_TJID='DL' and (T_TIME between '" + st + "' and '" + et + "') and T_ORGID='" + id + "' GROUP BY T_ORGID";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            return double.Parse(Convert.ToDouble(obj).ToString("f2"));
        }
        #endregion

        #region 累计发电小时
        public object GetInverternHour(string id)
        {
            strSql = "select T_HOURTTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() });
                else
                    dlVal = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() });
            return dlVal;
        }
        #endregion

        #region 1路输入电压
        public object GetInverternVpv1(string id)
        {
            strSql = "select T_VPV1TAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 2路输入电压
        public object GetInverternVpv2(string id)
        {
            strSql = "select T_VPV2TAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 1路输入电流
        public object GetInverternIpv1(string id)
        {
            strSql = "select T_IPV1TAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 2路输入电流
        public object GetInverternIpv2(string id)
        {
            strSql = "select T_IPV2TAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 累计发电量统计(所有逆变器)
        public DataTable GetSunDl(string id, string st, string et)
        {
            strSql = "select  SUM(D_VALUE) VAL,T_ORGID from T_INFO_STATISTICS where T_TJID='DL' and (T_TIME between '" + st + "' and '" + et + "') and T_ORGID in(select T_UNITID From T_BASE_UNIT where T_DISTRICTID in(select T_DISTRICTID from T_BASE_DISTRICT where T_ORGID='" + id + "')) group by T_ORGID";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        #endregion

        #region 平均功率
        public DataTable GetAvgPower(string id, string st, string et)
        {
            strSql = "select avg(D_VALUE) AVG,T_ORGID from T_INFO_STATISTICS where T_TJID='PJGL' and (T_TIME between '" + st + "' and '" + et + "') and T_ORGID in(select T_UNITID From T_BASE_UNIT where T_DISTRICTID in(select T_DISTRICTID from T_BASE_DISTRICT where T_ORGID='" + id + "')) group by T_ORGID";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        public double GetInverterAvgPower(string id, string st, string et)
        {
            strSql = "select ISNULL(avg(D_VALUE),0) AVG from T_INFO_STATISTICS where T_TJID='PJGL' and (T_TIME between '" + st + "' and '" + et + "') and T_ORGID ='" + id + "' GROUP BY T_ORGID";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            return Convert.ToDouble(obj);
        }
        #endregion

        #region 平均发电效率
        public DataTable GetAvgEfficiency(string id, string st, string et)
        {
            strSql = "select avg(D_VALUE) AVG,T_ORGID from T_INFO_STATISTICS where T_TJID='PR' and (T_TIME between '" + st + "' and '" + et + "') and T_ORGID in(select T_UNITID From T_BASE_UNIT where T_DISTRICTID in(select T_DISTRICTID from T_BASE_DISTRICT where T_ORGID='" + id + "')) group by T_ORGID";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        public double GetInverterAvgEfficiency(string id, string st, string et)
        {
            strSql = "select ISNULL(avg(D_VALUE),0) AVG from T_INFO_STATISTICS where T_TJID='PR' and (T_TIME between '" + st + "' and '" + et + "') and T_ORGID '" + id + "' GROUP BY T_ORGID";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            return Convert.ToDouble(obj);
        }
        #endregion

        #region 容量
        public double GetRL(string id)
        {
            dlVal = 0;
            strSql = "select top 1 isnull( D_RL,0) from T_BASE_MACHINE where T_MACHINEID =(select T_MACHINEID from T_BASE_UNIT where T_UNITID='" + id + "')";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            if (obj != null)
                dlVal = Convert.ToDouble(obj);
            return Convert.ToDouble(dlVal);
        }
        #endregion

        #region 实时效率
        public object GetRealEfficiency(string id)
        {
            strSql = "select T_NBQXLTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null)
                if (rtdbJudge == "1")
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() }));
                else
                    dlVal = Convert.ToDouble(iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() }));
            return dlVal;
        }
        #endregion

        #region 累计发电效率
        public double GetSumEfficiency(string id, string st, string et)
        {
            dlVal = 0;
            double sumDL = GetInverternElect(id, st, et);
            double sumfzd = GetSumIrradiance(id, st, et);
            double rl = GetRL(id);
            if (sumfzd * rl > 0)
                dlVal = sumDL * 1000 / (sumfzd * rl);

            return GetDouble(Convert.ToDouble(dlVal), 2);
        }
        #endregion

        #region 累计辐照度
        public double GetSumIrradiance(string id, string st, string et)
        {
            strSql = "select T_ORGID from T_BASE_DISTRICT where T_DISTRICTID =(select T_DISTRICTID from T_BASE_UNIT where T_UNITID='" + id + "')";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            StationDAL dal = new StationDAL();
            dlVal = dal.GetSumIrradiance(obj.ToString(), st, et);
            return GetDouble(Convert.ToDouble(dlVal), 2);
        }
        #endregion

        #region 日发电效率
        public object GetDayEfficiency(string id, string time)
        {
            strSql = "select D_VALUE from T_INFO_STATISTICS where T_TJID='DPR' and T_TIME ='" + time + "' and T_ORGID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            return GetDouble(Convert.ToDouble(obj), 2);
        }
        #endregion

        #region 月发电效率
        public object GetMonthEfficiency(string id, string time)
        {
            strSql = "select D_VALUE from T_INFO_STATISTICS where T_TJID='MPR' and T_TIME ='" + time + "' and T_ORGID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            //if (obj != null)
            //    dlVal = Convert.ToDouble(obj);
            return GetDouble(Convert.ToDouble(obj), 2);
        }
        #endregion

        #region 年发电效率
        public double GetYearEfficiency(string id, string time)
        {
            strSql = "select D_VALUE from T_INFO_STATISTICS where T_TJID='YPR' and T_TIME ='" + time + "' and T_ORGID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            if (obj != null)
                dlVal = Convert.ToDouble(obj);
            return GetDouble(Convert.ToDouble(dlVal), 2);
        }
        #endregion

        #region 大类故障次数
        public DataTable GetFaultRecordCount(string id, DateTime sTime, DateTime eTime)
        {
            strSql = @"select distinct ft.Num,ft.T_WATCHID,ft.T_ORGID,ft.T_UNITDESC_CN,ft.T_UNITDESC_EN,fa.T_FAULTRECORD_EN,fa.T_FAULTRECORD_CN From (select  f.Num,f.T_WATCHID,f.T_ORGID,b.T_UNITDESC_CN,b.T_UNITDESC_EN from (
select COUNT(*) NUM,T_WATCHID,T_ORGID From T_INFO_FAULTRECORD where T_WATCHID in(
select distinct T_TYPEID from T_BASE_FAULTPARA where T_MACHINEID =(select T_MACHINEID from T_BASE_UNIT where T_UNITID = '" + id + "')) and T_ORGID='" + id + "' and ";
            strSql += @"( ID_KEY not in (select ID_KEY from T_INFO_FAULTRECORD where T_ENDTIME <'" + sTime + "' or T_STARTTIME>'" + eTime + "')) group by T_ORGID,T_WATCHID) f left join T_BASE_UNIT b on f.T_ORGID=b.T_UNITID) ft left join T_BASE_FAULTPARA fa on ft.T_WATCHID=fa.T_TYPEID";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        #endregion

        #region 故障状态
        public double GetFaultState(string id)
        {
            strSql = "select T_FAULTTAG from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            if (obj != null && obj != "")
            {
                if (rtdbJudge == "1")
                    obj = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValue", new object[] { obj.ToString() });
                else
                    obj = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValueNoJudge", new object[] { obj.ToString() });
                if (obj != null && obj != "")
                {
                    return GetDouble(Convert.ToDouble(obj), 2);
                }
                else
                    return 0;
            }
            else
                return 0;
        }



        public double[] GetFaultStateArray(string id)
        {
            double[] d_vals = new double[1];
            string str_order = id.Replace("(", "").Replace(")", "").Replace("'", "");
            strSql = "select T_FAULTTAG from T_BASE_POINTS_UNIT where T_UNITID in  (" + id + ") order by CHARINDEX(',' + LTRIM(T_UNITID) + ',', '," + str_order + ",')";



            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });

            string[] str_arr = dt.AsEnumerable().Select(t => t.Field<string>("T_FAULTTAG")).ToArray();
            if (str_arr != null)
            {
                object d_vals1 = null;
                if (rtdbJudge == "1")
                    d_vals1 = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValues", new object[] { str_arr });
                else
                    d_vals1 = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValuesNoJudge", new object[] { str_arr });

                d_vals = (double[])d_vals1;
            }

            return d_vals;
        }


        public List<double[]> GetFaultPowerArray(string id)
        {
            List<double[]> val = new List<double[]>();
            double[] d_vals = new double[1];
            string str_order = id.Replace("(", "").Replace(")", "").Replace("'", "");
            strSql = "select T_FAULTTAG,T_NBQXLTAG,T_POWERTAG,T_ELECDTAG from T_BASE_POINTS_UNIT where T_UNITID in  (" + id + ") order by CHARINDEX(',' + LTRIM(T_UNITID) + ',', '," + str_order + ",')";


            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });

            string[] str_arr = dt.AsEnumerable().Select(t => t.Field<string>("T_FAULTTAG")).ToArray();
            List<string> l_data = new List<string>();
            List<string> l_data1 = new List<string>(str_arr);
            double[] d_val1 = new double[l_data1.Count];
            l_data.AddRange(l_data1);

            string[] str_arr1 = dt.AsEnumerable().Select(t => t.Field<string>("T_NBQXLTAG")).ToArray();
            l_data1 = new List<string>(str_arr1);
            double[] d_val2 = new double[l_data1.Count];
            l_data.AddRange(l_data1);
            string[] str_arr2 = dt.AsEnumerable().Select(t => t.Field<string>("T_POWERTAG")).ToArray();
            l_data1 = new List<string>(str_arr2);
            double[] d_val3 = new double[l_data1.Count];
            l_data.AddRange(l_data1);
            string[] str_arr3 = dt.AsEnumerable().Select(t => t.Field<string>("T_ELECDTAG")).ToArray();
            l_data1 = new List<string>(str_arr3);
            double[] d_val4 = new double[l_data1.Count];
            l_data.AddRange(l_data1);

            if (l_data != null)
            {
                object d_vals1 = null;

                if (rtdbJudge == "1")
                    d_vals1 = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValues", new object[] { l_data.ToArray() });
                else
                    d_vals1 = iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValuesNoJudge", new object[] { l_data.ToArray() });
                d_vals = (double[])d_vals1;
                for (int i = 0; i < d_val1.Length; i++)
                {
                    d_val1[i] = d_vals[i];
                }

                int num = 0;
                for (int i = d_val1.Length; i < d_val1.Length + d_val2.Length; i++)
                {
                    d_val2[num] = d_vals[i];
                    num++;
                }
                num = 0;
                for (int i = d_val1.Length + d_val2.Length; i < d_val1.Length + d_val2.Length + d_val3.Length; i++)
                {
                    d_val3[num] = d_vals[i];
                    num++;
                }
                num = 0;
                for (int i = d_val1.Length + d_val2.Length + d_val3.Length; i < d_vals.Length; i++)
                {
                    d_val4[num] = d_vals[i];
                    num++;
                }
            }
            val.Add(d_val1);
            val.Add(d_val2);
            val.Add(d_val3);
            val.Add(d_val4);


            return val;
        }


        #endregion

        #region UTC
        public static int DateTimeToUTC(DateTime DT)
        {
            long a = new DateTime(1970, 1, 1, 0, 0, 0, 0).Ticks;
            int rtnInt = 0;
            rtnInt = (int)((DT.Ticks - 8 * 3600 * 1e7 - a) / 1e7);
            return rtnInt;
        }
        #endregion

        #region 四舍五入
        /// <summary>
        /// 四舍五入
        /// </summary>
        /// <param name="result">要转换的数值</param>
        /// <param name="num">保留位数</param>
        /// <returns></returns>
        public double GetDouble(double result, int num)
        {
            if (!double.IsNaN(result))
            {
                string res = result.ToString();
                string results = "";
                int index = res.IndexOf('.');

                if (res.Length - index == num + 1)
                    return Convert.ToDouble(res);
                else
                {
                    if (index > 0)
                    {
                        index += num;
                        res = res + "000000000000000000";
                        res = res.Remove(0, index + 1);
                        results = result + "000000000000000000";
                        results = results.ToString().Substring(0, index + 1);
                        res = res.Substring(0, 1);

                        string point = "0.";

                        for (int count = 0; count < num - 1; count++)
                        {
                            point += "0";
                        }
                        point += "1";


                        if (Convert.ToInt32(res) > 4)
                        {
                            results = (Convert.ToDouble(results) + Convert.ToDouble(point)).ToString();
                            res = results;
                        }
                        else
                        {
                            res = results;
                        }
                    }
                    else
                    {
                        res += ".";
                        for (int i = 0; i < num; i++)
                        {
                            res += "0";
                        }
                    }
                    return Convert.ToDouble(res);
                }
            }
            else
                return result;
        }
        #endregion

        #region 逆变器负荷趋势
        //功率
        public double[] GetPowerInverterLine(string tag, DateTime sTime, DateTime eTime, int second)
        {
            double[] val = null;
            strSql = "select T_POWERTAG from T_BASE_POINTS_UNIT where T_UNITID='" + tag + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null && obj != DBNull.Value)
                val = (double[])iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValueByStep", new object[] { obj.ToString(), sTime, eTime, second });
            return val;
        }
        public double[][] GetPowerLine(string tag, DateTime sTime, DateTime eTime, int second)
        {
            //tag = tag.Replace("(", "").Replace(")", "").Replace("'", "");

            strSql = "select T_POWERTAG from T_BASE_POINTS_UNIT where T_UNITID in(" + tag + ")";

            double[][] val = null;

            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            string[] points = new string[dt.Rows.Count];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                points[i] = dt.Rows[i][0].ToString();
            }
            val = (double[][])iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValuesByStep", new object[] { points, sTime, eTime, second });

            return val; ;
        }
        //直流功率
        public double[] GetDCPowerInverterLine(string tag, DateTime sTime, DateTime eTime, int second)
        {
            double[] val = null;
            strSql = "select T_DCPTAG from T_BASE_POINTS_UNIT where T_UNITID='" + tag + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null && obj != DBNull.Value)
                val = (double[])iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValueByStep", new object[] { obj.ToString(), sTime, eTime, second });
            return val;
        }
        //交流功率
        public double[] GetACPowerInverterLine(string tag, DateTime sTime, DateTime eTime, int second)
        {
            double[] val = null;
            strSql = "select T_ACPTAG from T_BASE_POINTS_UNIT where T_UNITID='" + tag + "'";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });

            if (obj != null && obj != DBNull.Value)
                val = (double[])iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValueByStep", new object[] { obj.ToString(), sTime, eTime, second });
            return val;
        }
        #endregion

        #region 离散率曲线
        public double[][] GetDispersionRatioLine(string tag, DateTime sTime, DateTime eTime, int second)
        {
            //tag = tag.Replace("(", "").Replace(")", "");
            strSql = "select T_DISPERSIONRATIOTAG from T_BASE_POINTS_UNIT where T_UNITID in(" + tag + ")";

            double[][] val = null;

            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            string[] points = new string[dt.Rows.Count];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                points[i] = dt.Rows[i][0].ToString();
            }
            val = (double[][])iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetHistValuesByStep", new object[] { points, sTime, eTime, second });

            return val;
        }
        #endregion

        #region 逆变器详细信息
        public ArrayList GetInverterPointInfo(string id)
        {
            ArrayList list = new ArrayList();
            strSql = "select T_FIELD,T_DESC_CN,I_ORDER from T_BASE_UNITINFO where T_UNITID='" + id + "' order by I_ORDER asc";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });

            if (dt == null || dt.Rows.Count == 0)
                return list;

            string columns = "";
            string[] name = new string[dt.Rows.Count];
            string[] points = new string[dt.Rows.Count];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                name[i] = dt.Rows[i]["T_DESC_CN"].ToString();
                columns += dt.Rows[i]["T_FIELD"] + ",";
            }
            columns = columns.TrimEnd(',');
            strSql = "select " + columns + " from T_BASE_POINTS_UNIT where T_UNITID='" + id + "'";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                points[i] = dt.Rows[0][i].ToString();
            }
            list.Add(name);
            list.Add(points);

            return list;
        }
        #endregion


        #region  获取实时点数据
        public List<double[]> GetRealVal(string id, string[] name)
        {
            List<double[]> list = new List<double[]>();
            string column = "";
            string[] points = null;
            double[] val = null;
            for (int i = 0; i < name.Length; i++)
            {
                if (name[i] == "负荷")
                {
                    column += "T_POWERTAG,";
                }
                else if (name[i] == "电量")
                {
                    column += "T_ELECDTAG,";
                }
                else if (name[i] == "故障")
                {
                    column += "T_FAULTTAG,";
                }
                else if (name[i] == "效率")
                {
                    column += "T_NBQXLTAG,";
                }
                else if (name[i] == "电流")
                {
                    column += "T_IACRTAG,";
                }
            }

            if (column != "")
            {
                List<string> _points = new List<string>();
                column = column.Substring(0, column.Length - 1);

                string str_order = id.Replace("(", "").Replace(")", "").Replace("'", "");

                strSql = "select " + column + " from T_BASE_POINTS_UNIT where T_UNITID in(" + id + ") order by CHARINDEX(',' + LTRIM(T_UNITID) + ',', '," + str_order + ",')";


                dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
                if (dt != null && dt.Rows.Count > 0)
                {
                    points = new string[dt.Rows.Count];
                    val = new double[dt.Rows.Count];
                    for (int i = 0; i < name.Length; i++)
                    {
                        for (int k = 0; k < dt.Rows.Count; k++)
                        {
                            _points.Add(dt.Rows[k][i].ToString());

                        }
                    }
                    if (rtdbJudge == "1")
                        val = (double[])iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValues", new object[] { _points.ToArray() });
                    else
                        val = (double[])iw.RunWebService(rtdbRealTimeAddress, rtdbNameSpace, "GetRealValuesNoJudge", new object[] { _points.ToArray() });
                    List<double> list_val = new List<double>(val);

                    for (int i = 0; i < name.Length; i++)
                    {
                        val = new double[dt.Rows.Count];
                        for (int k = 0; k < dt.Rows.Count; k++)
                        {
                            val[k] = list_val[0];
                            list_val.RemoveAt(0);
                        }
                        list.Add(val);
                    }
                }
            }
            return list;
        }

        #endregion

        #region 获取逆变器额定功率
        public DataTable GetInverterRatedRL(string stationID)
        {
            strSql = @"select u.T_UNITID,u.T_UNITDESC_CN,m.D_RL From T_BASE_UNIT u left join T_BASE_MACHINE m on u.T_MACHINEID = m.T_MACHINEID where u.T_DISTRICTID in(select T_DISTRICTID from T_BASE_DISTRICT where T_ORGID='" + stationID + "') and m.T_TYPEID='nbq'  order by I_ORDER asc";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        public object GetRatedRL(string id)
        {
            strSql = @"select m.D_RL From T_BASE_UNIT u left join T_BASE_MACHINE m on u.T_MACHINEID = m.T_MACHINEID where u.T_UNITID = '" + id + "' and m.T_TYPEID = 'nbq' order by I_ORDER asc";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            return obj;
        }
        #endregion

        #region 获取电站编号
        public object GetStationID(string id)
        {
            strSql = "select T_ORGID From T_BASE_DISTRICT where T_DISTRICTID = (select T_DISTRICTID from T_BASE_UNIT where T_UNITID='" + id + "')";
            obj = iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunSingle", new object[] { strSql, strErrMsg });
            return obj;
        }
        #endregion
    }
}
